package com.hpeng.sys.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hpeng.sys.dao.SysTemplateDao;
import com.hpeng.sys.model.SysTemplate;
import com.hpeng.util.GenericDaoImpl;
import com.hpeng.util.Pagination;

@Component("sysTemplateDao")
public class SysTemplateDaoImpl extends GenericDaoImpl<SysTemplate, String>
		implements SysTemplateDao {

	public List<SysTemplate> getSysTemplates() {
		return this.getAll();
	}
	
	public List<SysTemplate> getSysTemplatesByName(String name){
		List<SysTemplate> sysTemplates = null;
		sysTemplates = getByHql("from SysTemplate sysTemplate where sysTemplate.templateName like '%"+name+"%'");
		return sysTemplates;
	}

	public Pagination<SysTemplate> getPagination(int pageNumber) {
		return getPagination("from SysTemplate order by seq desc", null,
				pageNumber);
	}
	
	public Pagination<SysTemplate> getPByTmpltName(String templateName,
			int pageNumber) {
		return getPagination("from SysTemplate as s where s.templateName like '%'|| ? ||'%' order by seq desc", new Object[]{templateName},
				pageNumber);
	}

	public void addSysTemplate(SysTemplate sysTemplate) {
		save(sysTemplate);
	}

	public SysTemplate findSysTemplate(String templateCode) {
		return get(templateCode);
	}

	public void updSysTemplate(SysTemplate sysTemplate) {
		update(sysTemplate);
	}

	public void delSysTemplate(String templateCode) {
		remove(templateCode);
	}

	public void delSysTemplateByIds(String... ids) {
		removeAllByIds(ids);
	}
	public SysTemplate getById(String id){
		return this.get(id);
	}
}